aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog/[...slug].astro
blob: 8c8aea929bfe48754f7f08d9d4b8404792e6a2e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
import Page from '../../layouts/BlogPost.astro';
import { getEntry, getCollection, render } from 'astro:content';
import { formatDate } from "../../util";

export async function getStaticPaths() {
  const posts = await getCollection('blog')
  return posts.map((post) => ({
    params: { slug: post.id },
    props: { post },
  }))
}

const { slug } = Astro.params;

if (slug === undefined) {
    throw new Error('Slug is required');
}

const entry = await getEntry('blog', slug);

if(entry === undefined) {
    return Astro.redirect('/404');
}

const { Content } = await render(entry);
---
<Page title={entry.data.title} description={entry.data.description} pubDate={formatDate(entry.data.pubDate)} tags={entry.data.tags}>
    <main>
        <a href="/blog" class="back-link">← All articles</a>
        <article>
            <Content />
        </article>
    </main>
</Page>

<style is:global>
    img {
        width: 45%;
    }

    @media (max-width: 768px) {
        img {
            width: 50%;
        }
    }
</style>